<template>
  <div class="ele-body">
    <!-- 搜索表单 -->
    <div class="block-interval">
      <a-card :bordered="false">
        <a-form layout="inline" :model="where">
          <a-row>
            <a-form-item label="开始时间:">
              <a-date-picker v-model:value="where.searchBeginTime" type="date" show-time format="YYYY-MM-DD HH:mm:ss" valueFormat="YYYY-MM-DD HH:mm:ss" />
            </a-form-item>
            <a-form-item label="结束时间:">
              <a-date-picker v-model:value="where.searchEndTime" type="date" show-time format="YYYY-MM-DD HH:mm:ss" valueFormat="YYYY-MM-DD HH:mm:ss" />
            </a-form-item>

            <a-form-item label="所属事件源:" name="sourceId">
              <a-select
                show-search
                v-model:value="where.sourceId"
                placeholder="请选择所属事件源"
                style="width: 205px;"
                :show-arrow="false"
                :filter-option="false"
                :not-found-content="null"
              >
                <a-select-option v-for="item in sourceList" :key="item.sourceId" >
                  {{ item.thirdName }}
                </a-select-option>
              </a-select>
            </a-form-item>

            <a-form-item class="ele-text-center">
              <a-space>
                <a-button type="primary" @click="reload">查询</a-button>
                <a-button @click="reset">重置</a-button>
              </a-space>
            </a-form-item>

          </a-row>
        </a-form>
      </a-card>
    </div>

    <!-- 表格 -->
    <div>
      <a-card :bordered="false">
        <ele-pro-table
          ref="table"
          row-key="trieId"
          :datasource="datasource"
          :columns="columns"
          :where="where"
          v-model:selection="selection"
          :scroll="{ x: 'max-content' }"
        >

          <template #bodyCell="{ column, record }">
            <template v-if="column.key === 'eventIdColumn'" >
              <span v-if="record.monitorEventDTO != null">
                <span>{{record.monitorEventDTO.eventName}}</span>
                <br/>
                <span>{{record.monitorEventDTO.eventType}}</span>
              </span>
              <span v-else>-</span>
            </template>

            <template v-if="column.key === 'sourceIdColumn'" >
              <span v-if="record.monitorEventSourceDTO != null">
                <span>{{record.monitorEventSourceDTO.thirdName}}</span>
                <br/>
                <span>{{record.monitorEventSourceDTO.thirdCode}}</span>
              </span>
              <span v-else>-</span>
            </template>
            <!-- table操作栏按钮 -->
            <template v-if="column.key === 'action'">
              <a-space>
                <a-popconfirm title="确定要删除此记录吗？" @confirm="remove(record)">
                  <a class="ele-text-danger">删除</a>
                </a-popconfirm>
              </a-space>
            </template>
          </template>
        </ele-pro-table>
      </a-card>
    </div>
  </div>
</template>

<script>
import { PlusOutlined } from '@ant-design/icons-vue';
import { message } from 'ant-design-vue';
import {MonitorEventSourceApi} from "@/api/monitors/MonitorEventSourceApi";
import {MonitorEventTriggerLogApi} from "@/api/monitors/MonitorEventTriggerLogApi";
export default {
  name: 'MonitorsEventTriggerlog',
  components: {
    PlusOutlined,
  },
  async mounted() {
  },
  data() {
    return {
      // 表格列配置
      columns: [
        {
          title: '事件发生时间',
          dataIndex: 'createTime'
        },
        {
          title: '事件源',
          dataIndex: 'sourceId',
          key: 'sourceIdColumn'
        },
        {
          title: '事件',
          dataIndex: 'eventId',
          key: 'eventIdColumn'
        },
        {
          title: '操作',
          key: 'action',
          width: 280,
          align: 'center'
        }
      ],
      // 表格搜索条件
      where: {},
      // 表格选中数据
      selection: [],
      // 当前编辑数据
      current: null,
      // 是否显示编辑弹窗
      showEdit: false,
      showEditContact : false,
      sourceList : []
    };
  },
  async created() {
    MonitorEventSourceApi.list({}).then(resp => {
      let _sourceList = (resp ? resp.data : null) || [];
      this.sourceList = _sourceList;
    });
  },
  methods: {
    /**
     * 搜索按钮
     *
     * @author cancan
     * @date 2024/12/15 16:16
     */
    reload() {
      this.selection = [];
      this.$refs.table.reload({ page: 1 });
    },

    /**
     * 重置搜索
     *
     * @author cancan
     * @date 2024/12/15 16:16
     */
    reset() {
      this.where.sourceId = '';
      this.where.searchBeginTime = '';
      this.where.searchEndTime = '';
      this.$nextTick(() => {
        this.reload();
      });
    },

    /**
     * 删除
     *
     * @author cancan
     * @date 2024/12/15 16:16
     */
    async remove(row) {
      const result = await MonitorEventTriggerLogApi.delete({ trieId: row.trieId });
      message.success(result.message);
      this.reload();
    },


    /**
     * 获取表格数据
     *
     * @author fengshuonan
     * @date 2022/5/8 15:18
     */
    datasource({ page, limit, where, orders }) {
      return MonitorEventTriggerLogApi.findPage({ ...where, ...orders, pageNo: page, pageSize: limit });
    }
  }
};
</script>
